if (require("PageRank")) {
library(PageRank)
}else{
devtools::install_github("ryangreenup/PageRank")
library(PageRank)
}
library(pacman)
pacman::p_load(PageRank, devtools, Matrix, igraph, mise, tidyverse, rgl, latex2exp)
# mise()
Define some constants
n <- 20
p <- 1:n/n
beta <- 1:n/n
beta <- runif(n)*100
#sz <- 1:n/n+10
sz <- (1:n/n)*100+10
input_var <- expand.grid("n" = n, "p" = p, "beta" = beta, "size" = sz)
input_var
random_graph <- function(n, p, beta, size) {
g1 <- igraph::erdos.renyi.game(n = sz, p)
A <- igraph::get.adjacency(g1) # Row to column
A <- Matrix::t(A)
A_dens <- mean(A)
T <- PageRank::power_walk_prob_trans(A)
tr <- sum(diag(T))
e2 <- eigen(T, only.values = TRUE)$values[2] # R orders by descending magnitude
A_det <- det(T)
return(c(abs(e2), A_dens, A_det, tr))
}
Map the function
nc <- length(random_graph(1, 1, 1, 1))
Y <- matrix(ncol = nc, nrow = nrow(input_var))
for (i in 1:nrow(input_var)) {
X <- as.vector(input_var[i,])
Y[i,] <- random_graph(X$n, X$p, X$beta, X$size)
}
if (sum(abs(Y) != abs(Re(Y))) == 0) {
Y <- Re(Y)
}
nrow(input_var)
[1] 8000
nrow(Y)
[1] 8000
Y <- as.data.frame(Y); colnames(Y) <- c("eigenvalue2", "density", "determinant", "trace")
(data <- cbind(input_var, Y)) %>% head()
data <- data[data$density!=0,]
mod <- lm(eigenvalue2 ~ poly(density, 1), data = data)
mod$residuals %>% hist(breaks = 90)
hist(rnorm(3000), breaks = 100)
plot(mod)
NA
This is interesting, lets look at a snapshot of it:
pairs(data)
cor(data)
the standard deviation is zero
n p
n 1 NA
p NA 1.0000000000
beta NA -0.0003878828
size NA 0.0002679644
eigenvalue2 NA -0.9212105217
density NA 0.9904278229
determinant NA -0.0165548871
trace NA -0.8625597471
beta size
n NA NA
p -0.0003878828 0.0002679644
beta 1.0000000000 0.0003062037
size 0.0003062037 1.0000000000
eigenvalue2 0.0019516406 -0.0001260856
density 0.0007147401 0.0013455370
determinant 0.0014073128 0.0031502969
trace -0.0017016803 -0.0040214793
eigenvalue2 density
n NA NA
p -0.9212105217 0.9904278229
beta 0.0019516406 0.0007147401
size -0.0001260856 0.0013455370
eigenvalue2 1.0000000000 -0.9287234046
density -0.9287234046 1.0000000000
determinant 0.0211222176 -0.0164753631
trace 0.6696925620 -0.8728746605
determinant trace
n NA NA
p -0.016554887 -0.862559747
beta 0.001407313 -0.001701680
size 0.003150297 -0.004021479
eigenvalue2 0.021122218 0.669692562
density -0.016475363 -0.872874661
determinant 1.000000000 -0.005188244
trace -0.005188244 1.000000000
library(corrplot)
corrplot(cor(data), method = "ellipse", type = "lower")
the standard deviation is zero
names(data)
[1] "n" "p"
[3] "beta" "size"
[5] "eigenvalue2" "density"
[7] "determinant" "trace"
library(scatterplot3d)
shapes = c(16, 17, 18)
shapes <- shapes[as.numeric(iris$Species)]
scatterplot3d(iris[,1:3], pch = shapes)
d <- data[,names(data) %in% c("eigenvalue2", "density", "determinant")]
scatterplot3d(d, angle = 10)
library(plotly)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
d <- data[sample(1:nrow(data), 1000),]
fig <- plot_ly(d, x = ~determinant, y = ~density, z = ~eigenvalue2)
fig <- fig %>% add_markers(size = 1)
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig
NA
ggplot(data) +
geom_point(mapping = aes(x = density, y = eigenvalue2, size = beta, color = size )) +
scale_size_continuous(range = c(0.1,1)) +
labs(x = "Density of Adjacency Matrix", y = TeX("$\\xi_2$ of $T_{PW}$")) +
guides(size = FALSE, col = FALSE)
well the spread is heteroskedastic so let’s log transform it:
ggplot(data, aes(x = density, y = log(eigenvalue2))) +
geom_point(mapping = aes(size = size, color = p, shape = factor(n))) +
# stat_smooth() +
scale_size_continuous(range = c(0.1,1.5)) +
labs(x = "Density of Adjacency Matrix", y = "Second Eigenvalue of Power Walk Transition Probability Matrix")
We could probably model this with a quadratic:
mod_x1 <- lm(log(eigenvalue2) ~ poly(density, 1), data = data)
data$x1 <- predict(mod_x1)
mod_x2 <- lm(log(eigenvalue2) ~ poly(density, 2), data = data)
data$x2 <- predict(mod_x2)
mod_x4 <- lm(log(eigenvalue2) ~ poly(density, 4), data = data)
data$x4 <- predict(mod_x4)
mod_xl <- lm(log(eigenvalue2) ~ log(1-density), data = data)
data$xl <- predict(mod_xl)
mod_df <- data
mod_df_long <- pivot_longer(mod_df, cols = c(x1, x2, x4, xl), names_to = "Model_Type", values_to = "eigenvalue2_mod")
mod_df_long$eigenvalue2_log <- log(mod_df_long$eigenvalue2)
print(c("MSE Linear" = mean(mod_x1$residuals^2),
"MSE Quadratic" = mean(mod_x2$residuals^2),
"MSE Quartic" = mean(mod_x4$residuals^2),
"MSE Logarithmic" = mean(mod_xl$residuals^2)
), 2)
MSE Linear MSE Quadratic MSE Quartic MSE Logarithmic
0.078 0.031 0.013 0.023
ggplot(mod_df_long, aes(x = density)) +
geom_point(aes(y = eigenvalue2_log), fill = "lightblue", col = "black", size = 0.1, alpha = 0.2) +
geom_smooth(aes(y = eigenvalue2_mod, col = Model_Type), size = 0.9) +
labs(col = c("Model \nType")) +
scale_color_discrete(labels = c("Linear", "Quadratic", "Quartic", "Logarithmic")) +
labs(x = "Density of A", y = TeX("$\\log \\left( \\xi_2 \\right$ of $\\mathbf{T}$")) +
theme_linedraw()
data.frame("Model" = c("Linear", "Logarithmic"))
ggplot()
# TODO Change the colour of each model by using pivot_longer
# TODO Make a plot of degree vs RSS, comment that the lack of elbo is evidence to regect
# TODO Try a negative log, any luck? with that
# TODO Does this vary by beta?
# TODO Write it up in a report
# DONE What about a sqrt transform and then a linear model?
# Leaves too much variance
ggplot(data, aes(x = density, y = log(eigenvalue2))) +
geom_point(mapping = aes(size = size, alpha = 0.01, color = size, shape = factor(n))) +
# stat_smooth() +
scale_size_continuous(range = c(0.1,1.5)) +
labs(x = "Density of Adjacency Matrix [ mean(A) ]", y = TeX("$\\log\\left( \\xi_2 \\right)$ of T")) +
geom_line(aes(x = density, y = x1, lwd = 2)) +
geom_line(aes(x = density, y = xl, lwd = 3))
# geom_line(aes(x = density, y = x3, lwd = 0.5)) +
# geom_line(aes(x = density, y = x4, lwd = 0.5)) +
# geom_line(aes(x = density, y = x5, lwd = 0.5)) +
# geom_line(aes(x = density, y = x6, lwd = 36))
ggplot(data, aes(x = trace , y = log(eigenvalue2))) +
geom_point(mapping = aes(size = size, color = p, shape = factor(n))) +
# stat_smooth() +
scale_size_continuous(range = c(0.1,1.5)) +
labs(x = "Trace of Transition Matrix", y = TeX("$\\log\\left( \\xi_2 \\right)$ of \\mathbf{W}"))
mod_df <- data
mod_hyp <- lm(log(eigenvalue2) ~ I(trace^(-1)), data = data)
mod_df$hyp <- predict(mod_hyp)
mod_log <- lm(log(eigenvalue2) ~ log(trace), data = data)
mod_df$log <- predict(mod_log)
ggplot(mod_df, aes(x = trace, y = log(eigenvalue2))) +
geom_point(mapping = aes(size = size, alpha = 0.01, color = size, shape = factor(n))) +
# stat_smooth() +
scale_size_continuous(range = c(0.1,1.5)) +
labs(x = "Trace of A", y = TeX("$\\log\\left( \\xi_2 \\right)$ of T")) +
geom_line(aes(x = trace, y = hyp, lwd = 2)) +
geom_line(aes(x = trace, y = log, lwd = 2))
mod_df <- data
mod_hyp <- lm(log(eigenvalue2) ~ 0 + I(trace^(-1)), data = data)
mod_df$hyp <- predict(mod_hyp)
mod_log <- lm(log(eigenvalue2) ~ 0 + log(trace), data = data)
mod_df$log <- predict(mod_log)
mod_df_long <- pivot_longer(mod_df, cols = c(hyp, log), names_to = "Model_Type", values_to = "eigenvalue2_mod")
mod_df_long$eigenvalue2_log <- log(mod_df_long$eigenvalue2)
print(c("MSE Hyperbolic" = mean(mod_hyp$residuals^2),
"MSE Logarithmic" = mean(mod_log$residuals^2)), 2)
ggplot(mod_df_long, aes(x = trace)) +
geom_point(shape = 23, aes(y = eigenvalue2_log), fill = "lightblue", col = "black", size = 0.7, alpha = 0.4) +
geom_line(aes(y = eigenvalue2_mod, col = Model_Type), size = 1) +
labs(col = c("Model \nType")) +
scale_color_manual(labels = c("Hyperbolic", "Logarithmic"),
values = c("indianred", "royalblue")) +
labs(x = "Trace of A", y = TeX("$\\log \\left( \\xi_2 \\right$ of $\\mathbf{T}$"))
theme_linedraw()
List of 93
$ line :List of 6
..$ colour : chr "black"
..$ size : num 0.5
..$ linetype : num 1
..$ lineend : chr "butt"
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ rect :List of 5
..$ fill : chr "white"
..$ colour : chr "black"
..$ size : num 0.5
..$ linetype : num 1
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ text :List of 11
..$ family : chr ""
..$ face : chr "plain"
..$ colour : chr "black"
..$ size : num 11
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : num 0
..$ lineheight : num 0.9
..$ margin : 'margin' num [1:4] 0points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ title : NULL
$ aspect.ratio : NULL
$ axis.title : NULL
$ axis.title.x :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 2.75points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.x.top :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 2.75points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.x.bottom : NULL
$ axis.title.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : num 90
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 2.75points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.title.y.left : NULL
$ axis.title.y.right :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : num -90
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 0points 2.75points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : chr "black"
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 2.2points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x.top :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : num 0
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 2.2points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.x.bottom : NULL
$ axis.text.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 1
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 2.2points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.text.y.left : NULL
$ axis.text.y.right :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 0points 2.2points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ axis.ticks :List of 6
..$ colour : chr "black"
..$ size : 'rel' num 0.5
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ axis.ticks.x : NULL
$ axis.ticks.x.top : NULL
$ axis.ticks.x.bottom : NULL
$ axis.ticks.y : NULL
$ axis.ticks.y.left : NULL
$ axis.ticks.y.right : NULL
$ axis.ticks.length : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ axis.ticks.length.x : NULL
$ axis.ticks.length.x.top : NULL
$ axis.ticks.length.x.bottom: NULL
$ axis.ticks.length.y : NULL
$ axis.ticks.length.y.left : NULL
$ axis.ticks.length.y.right : NULL
$ axis.line : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ axis.line.x : NULL
$ axis.line.x.top : NULL
$ axis.line.x.bottom : NULL
$ axis.line.y : NULL
$ axis.line.y.left : NULL
$ axis.line.y.right : NULL
$ legend.background :List of 5
..$ fill : NULL
..$ colour : logi NA
..$ size : NULL
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ legend.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
..- attr(*, "unit")= int 8
$ legend.spacing : 'simpleUnit' num 11points
..- attr(*, "unit")= int 8
$ legend.spacing.x : NULL
$ legend.spacing.y : NULL
$ legend.key :List of 5
..$ fill : chr "white"
..$ colour : logi NA
..$ size : NULL
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ legend.key.size : 'simpleUnit' num 1.2lines
..- attr(*, "unit")= int 3
$ legend.key.height : NULL
$ legend.key.width : NULL
$ legend.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.text.align : NULL
$ legend.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ legend.title.align : NULL
$ legend.position : chr "right"
$ legend.direction : NULL
$ legend.justification : chr "center"
$ legend.box : NULL
$ legend.box.just : NULL
$ legend.box.margin : 'margin' num [1:4] 0cm 0cm 0cm 0cm
..- attr(*, "unit")= int 1
$ legend.box.background : list()
..- attr(*, "class")= chr [1:2] "element_blank" "element"
$ legend.box.spacing : 'simpleUnit' num 11points
..- attr(*, "unit")= int 8
$ panel.background :List of 5
..$ fill : chr "white"
..$ colour : logi NA
..$ size : NULL
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ panel.border :List of 5
..$ fill : logi NA
..$ colour : chr "black"
..$ size : 'rel' num 1
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ panel.spacing : 'simpleUnit' num 5.5points
..- attr(*, "unit")= int 8
$ panel.spacing.x : NULL
$ panel.spacing.y : NULL
$ panel.grid :List of 6
..$ colour : chr "black"
..$ size : NULL
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ panel.grid.major :List of 6
..$ colour : NULL
..$ size : 'rel' num 0.1
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ panel.grid.minor :List of 6
..$ colour : NULL
..$ size : 'rel' num 0.05
..$ linetype : NULL
..$ lineend : NULL
..$ arrow : logi FALSE
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_line" "element"
$ panel.grid.major.x : NULL
$ panel.grid.major.y : NULL
$ panel.grid.minor.x : NULL
$ panel.grid.minor.y : NULL
$ panel.ontop : logi FALSE
$ plot.background :List of 5
..$ fill : NULL
..$ colour : chr "white"
..$ size : NULL
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ plot.title :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.title.position : chr "panel"
$ plot.subtitle :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : num 0
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 0.8
..$ hjust : num 1
..$ vjust : num 1
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.caption.position : chr "panel"
$ plot.tag :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : 'rel' num 1.2
..$ hjust : num 0.5
..$ vjust : num 0.5
..$ angle : NULL
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ plot.tag.position : chr "topleft"
$ plot.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
..- attr(*, "unit")= int 8
$ strip.background :List of 5
..$ fill : chr "black"
..$ colour : NULL
..$ size : NULL
..$ linetype : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ strip.background.x : NULL
$ strip.background.y : NULL
$ strip.placement : chr "inside"
$ strip.text :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : chr "white"
..$ size : 'rel' num 0.8
..$ hjust : NULL
..$ vjust : NULL
..$ angle : NULL
..$ lineheight : NULL
..$ margin : 'margin' num [1:4] 4.4points 4.4points 4.4points 4.4points
.. ..- attr(*, "unit")= int 8
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ strip.text.x : NULL
$ strip.text.y :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : NULL
..$ angle : num -90
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
$ strip.switch.pad.grid : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ strip.switch.pad.wrap : 'simpleUnit' num 2.75points
..- attr(*, "unit")= int 8
$ strip.text.y.left :List of 11
..$ family : NULL
..$ face : NULL
..$ colour : NULL
..$ size : NULL
..$ hjust : NULL
..$ vjust : NULL
..$ angle : num 90
..$ lineheight : NULL
..$ margin : NULL
..$ debug : NULL
..$ inherit.blank: logi TRUE
..- attr(*, "class")= chr [1:2] "element_text" "element"
- attr(*, "class")= chr [1:2] "theme" "gg"
- attr(*, "complete")= logi TRUE
- attr(*, "validate")= logi TRUE
NOPE
chival <- dchisq(seq(from = 0, to = 40, length.out = 100), df = 10)*7
index <- seq(from = 0, to = 2.2, length.out = 100)
chidata <- data.frame(index = index, chi = chival)
ggplot(data) +
geom_point(mapping = aes(x = density, y = eigenvalue2, size = beta, color = size, shape = factor(n))) +
geom_line(data = chidata, mapping = aes(x = index, y = chi)) +
scale_size_continuous(range = c(0.1,1)) +
labs(x = "Density of Adjacency Matrix", y = "Second Eigenvalue of Power Walk Transition Probability Matrix")
constants:
n <- 20
p <- 1:n/n
beta <- 1:n/n
beta <- runif(n)*100
sz <- ((1:n)/n)*100+10
input_var <- expand.grid("n" = n, "p" = p, "beta" = beta, "size" = sz)
functions:
random_graph <- function(n, p, beta, size) {
g1 <- igraph::erdos.renyi.game(n = sz, p)
A <- igraph::get.adjacency(g1) # Row to column
A <- Matrix::t(A)
A_dens <- mean(A)
T <- PageRank::power_walk_prob_trans(A)
e2 <- eigen(T, only.values = TRUE)$values[2] # R orders by descending magnitude
A_det <- det(A)
return(c(abs(abs(e2)-0.4), abs(A_det), A_dens))
}
Map the function
nc <- length(random_graph(1, 1, 1, 1))
Y <- matrix(ncol = nc, nrow = nrow(input_var))
for (i in 1:nrow(input_var)) {
X <- as.vector(input_var[i,])
Y[i,] <- random_graph(X$n, X$p, X$beta, X$size)
}
if (sum(abs(Y) != abs(Re(Y))) == 0) {
Y <- Re(Y)
}
nrow(input_var)
nrow(Y)
Y <- as.data.frame(Y); colnames(Y) <- c("eigenvalue2", "determinant")
data <- cbind(input_var, Y)
ggplot(data) +
geom_point(mapping = aes(x = determinant, y = eigenvalue2, size = size, color = beta, shape = factor(n))) +
scale_size_continuous(range = c(0.1,1)) +
labs(y = "||e2|-0.4|", x = TeX("$\\left\\lvert A \\right\\rvert $"))
g1 <- igraph::erdos.renyi.game(n = sz, p)
coords <- layout_with_fr(g1, dim = 3)
# plot(g1)
rglplot(g1, layout=coords, size = 0.1)
## Not run:
g <- make_lattice( c(5,5,5) )
coords <- layout_with_fr(g, dim=3)
rglplot(g, layout=coords)
## End(Not run)
n <- sz <- size <- 10^3
p <- 0.
g1 <- igraph::erdos.renyi.game(n = sz, p)
A <- igraph::get.adjacency(g1) # Row to column
A <- Matrix::t(A)
det(A)
ggplot(data) +
geom_point(mapping = aes(x = size, y = determinant, size = size, color = beta, shape = factor(n))) +
scale_size_continuous(range = c(0.1,1)) +
labs(x = "size", y = "determinant")
constants:
n <- 10
p <- 1:n/n
beta <- 1:n/n
beta <- runif(n)*100
sz <- 1:n/n+100
input_var <- expand.grid("n" = n, "p" = p, "beta" = beta, "size" = sz)
functions:
random_graph <- function(n, p, beta, size) {
g1 <- igraph::erdos.renyi.game(n = sz, p)
A <- igraph::get.adjacency(g1) # Row to column
A <- Matrix::t(A)
A_dens <- mean(A)
T <- PageRank::power_walk_prob_trans(A)
e2 <- eigen(T, only.values = TRUE)$values[2] # R orders by descending magnitude
A_det <- det(A)
return(c(abs(e2), A_det, A_dens))
}
Map the function
nc <- length(random_graph(1, 1, 1, 1))
Y <- matrix(ncol = nc, nrow = nrow(input_var))
for (i in 1:nrow(input_var)) {
X <- as.vector(input_var[i,])
Y[i,] <- random_graph(X$n, X$p, X$beta, X$size)
}
if (sum(abs(Y) != abs(Re(Y))) == 0) {
Y <- Re(Y)
}
nrow(input_var)
nrow(Y)
Y <- as.data.frame(Y); colnames(Y) <- c("eigenvalue2", "determinant")
data <- cbind(input_var, Y)
chival <- dchisq(seq(from = 0, to = 40, length.out = 100), df = 10)*7
index <- seq(from = 0, to = 2.2, length.out = 100)
chidata <- data.frame(index = index, chi = chival)
ggplot(data) +
geom_point(mapping = aes(x = determinant, y = eigenvalue2, size = size, color = beta, shape = factor(n))) +
scale_size_continuous(range = c(0.1,1)) +
labs(x = "Density of Adjacency Matrix", y = "Second Eigenvalue of Power Walk Transition Probability Matrix")
g1 <- igraph::erdos.renyi.game(n = sz, p)
coords <- layout_with_fr(g1, dim = 3)
# plot(g1)
# rglplot(g1, layout=coords, size = 0.1)
## Not run:
g <- make_lattice( c(5,5,5) )
coords <- layout_with_fr(g, dim=3)
rglplot(g, layout=coords)
## End(Not run)
n <- sz <- size <- 100
p <- 0.4
g1 <- igraph::erdos.renyi.game(n = sz, p)
A <- igraph::get.adjacency(g1) # Row to column
A <- Matrix::t(A)
det(A)